//
//  HJCRefreshView.swift
//  新浪微博Swift
//
//  Created by 郝俊聪 on 15/5/21.
//  Copyright (c) 2015年 heima. All rights reserved.
//

import UIKit

class HJCRefreshView: UIView {

    @IBOutlet weak var pullView: UIView!
    
    @IBOutlet weak var pullImageView: UIImageView!

    @IBOutlet weak var pullTextLbl: UILabel!
    
    @IBOutlet weak var loadView: UIView!
    
    @IBOutlet weak var loadImageView: UIImageView!
    
    @IBOutlet weak var loadTextLbl: UILabel!
    
    
    
    func startLoadingAnimation(){
        
//         println("开始动画")
         self.pullView.hidden = true
        
//         self.loadImageView
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = M_PI*2
        anim.repeatCount = MAXFLOAT
        anim.duration = 5
        loadImageView.layer.addAnimation(anim, forKey: nil)
    
    }
    
    func endLoadingAnimation(){
        self.pullView.hidden = false
        loadImageView.layer.removeAllAnimations()
    }
    
    
    func rotatePullImageView(isLettingOut:Bool){
    
         //旋转180度
        if isLettingOut{
            
            UIView.animateWithDuration(0.5){ () -> Void in
                self.pullImageView.transform = CGAffineTransformRotate(self.pullImageView.transform, CGFloat(M_PI))
                self.pullTextLbl.text = "释放更新"
            }
            
        }else{
            UIView.animateWithDuration(0.5){ () -> Void in
                self.pullImageView.transform = CGAffineTransformRotate(self.pullImageView.transform, CGFloat(-M_PI))
                self.pullTextLbl.text = "下拉刷新"

             }
        }
        
    }
    
}



